﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class admin_userList : System.Web.UI.Page
{
    private Maticsoft.BLL.userinfo userBLL = new Maticsoft.BLL.userinfo();

    private static readonly int pagesize = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        int pagesize = 1;
        int pageIndex = Convert.ToInt32(hfdPage.Value);
        DataTable dt = userBLL.GetListByPage("", "id", (pageIndex - 1) * pagesize, pagesize * pageIndex).Tables[0];
        int totalCount = userBLL.GetAllList().Tables[0].Rows.Count;
        lblTotal.Text = totalCount + "";
        lblCurrentPage.Text = pageIndex + "";
        hfdMaxPage.Value = (totalCount % pagesize == 0) ? (totalCount / pagesize) + "" : (totalCount / pagesize + 1) + "";
        LoadTable(dt);
    }

    private void LoadTable(System.Data.DataTable dt)
    {
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow dataRow = dt.Rows[i];
            HtmlTableRow row = new HtmlTableRow();
            HtmlTableCell cell_userName = new HtmlTableCell();
            HtmlTableCell cell_state = new HtmlTableCell();
            HtmlTableCell cell_loginCode = new HtmlTableCell();
            HtmlTableCell cell_password = new HtmlTableCell();
            HtmlTableCell cell_operation = new HtmlTableCell();
            cell_userName.InnerText = dataRow["username"] + "";
            cell_state.InnerText = dataRow["state"] + "";
            cell_loginCode.InnerText = dataRow["loginCode"] + "";
            cell_password.InnerText = dataRow["password"] + "";
            string id = dataRow["id"] + "";
            cell_operation.InnerHtml = "<a href='addEditUser.aspx?id=" + id + "'><img src='img/editor.png'></a>" +
                                       "&nbsp;&nbsp;&nbsp;&nbsp;" +
                                       "<a href='#' class='del' id=" + id + "><img src='img/delete.png'></a> ";
            row.Cells.Add(cell_userName);
            row.Cells.Add(cell_state);
            row.Cells.Add(cell_loginCode);
            row.Cells.Add(cell_password);
            row.Cells.Add(cell_operation);
            userTable.Rows.Add(row);
        }
    }
    public bool deleteUser(object id)
    {

        return userBLL.Delete(10);
    }

}